<template>
    <view class="page-home-index">
        <u-sticky>
                <u-cell-group>
                    <u-cell-item :title="actionSheet.guildName" @click="actionSheet.isShow = true;"></u-cell-item>
                </u-cell-group>
		</u-sticky>
        <view class="p-4" v-if="longList.list.length == 0">
            <u-empty text="暂无内容" mode="list"></u-empty>
        </view>
		<view class="fly-card" v-else>
            <view class="item" v-for="(item,index) in longList.list" :key="index" @click="proxy.$util.gotoPage('/packageB/activity/examineDetail',{id:item.id})">
                <view class="thumb">
                    <u-image width="100%" height="300rpx" :src="proxy.$util.getFullImage(item.coverImageUrl)"></u-image>
                </view>
                <view class="content">
                    <view class="title font-bold ellipsis-1">{{ item.activitiesName }}</view>
                    <view class="flex-between mt-2 mb-3">
                        <view class="tags">
                            <u-tag class="tag-cyan tag-noborder mr-1" :text="proxy.$util.setName(item.activitiesType, optionData.activitiesType)" />
                            <u-tag v-if="item.isCheckinRequired == '1'" class="tag-red tag-noborder" text="签到" />
                        </view>
                        <!-- <view class="grey9"><u-icon name="map"></u-icon>0.5km</view> -->
                    </view>
                    <view class="desc">
                        <view>时间：<text class="c-black">{{ dayjs(item.startTime).format('MM/DD HH:mm') }} {{ proxy.$util.getWeekName(dayjs(item.startTime).day()) }}</text></view>
                        <view class="ellipsis-1">地点：<text class="c-black">{{ item.address || '线上'  }}</text></view>
                        <view>报名：<text class="c-black">{{ item.maxParticipants }}</text></view>
                    </view>
                </view>
            </view>
        </view>
        <u-action-sheet :list="actionSheet.list" v-model="actionSheet.isShow" @click="selectActionSheet"></u-action-sheet>

    </view>
</template>
<script setup lang="ts">
import dayjs from 'dayjs';
import {onShow, onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
import { useLonglist } from '@/static/fn/longList';
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
const initObj = {
    listApi: '/admin/activities/xcxPage'
}
let { searchForm, longList, getList} = useLonglist(initObj);
import { useAppStore } from '@/stores/app';
import { useOptionData } from '@/stores/optionData';
const appStore = useAppStore();
const optionDataStore = useOptionData();
let optionData = reactive({});
let actionSheet = reactive({
    isShow: false,
    guildListApi: '/admin/guilds/getGuildsByUserId',
    guildName: '所有分会',
    guildId: null,
    list: [],
})
const getInitData = async () => {
  let activitiesType = await optionDataStore.getDictList('activitie_type');
  optionData.activitiesType = activitiesType;
  let guildList = await proxy.$http('get', actionSheet.guildListApi, {});
  actionSheet.list = guildList.map(item => {
    return {id: item.guildId, text: item.guildName};
  });
  actionSheet.list.unshift({id: null,text: '所有分会'})
  console.log(optionData);
}
const selectActionSheet = (i) => {
    let obj = actionSheet.list[i];
    actionSheet.guildId = obj.id;
    actionSheet.guildName = obj.text;
    searchForm.guildId = obj.id;
    getList('refresh');
}
onPullDownRefresh(() => {
	getList('refresh');
	setTimeout( () => {
		uni.stopPullDownRefresh();
	}, 1000);
});
onReachBottom(() =>{
	getList();
});
onLoad(e => {
    if(e.type== 'isMaster'){
		actionSheet.guildlistApi = '/admin/guilds/getFenHUiGuildsByUserId'
	}
});
onShow(() => {
	searchForm.status = 1;
    // searchForm.guildId = '1804169217';
    getInitData();
	getList('refresh');
})
</script>